<?php

namespace models\DAO;

use models\Exception\DAO\ModelDriverException;
use models\Exception\DAO\ModelException;
use models\Exception\DAO\ModelReflectionException;
use models\Exception\DAO\ModelSqlException;


/**
 * @SWG\Swagger(
 *     @SWG\Definition(
 *          type="object",
 *          definition="alibabaproductSingleData",
 *          required={"errno", "errmsg", "data"},
 *          @SWG\Property(property="errno", type="integer", format="int32", description="编码"),
 *          @SWG\Property(property="errmsg", type="string", format="string", description="错误提示信息"),
 *          @SWG\Property(property="result", type="object", ref="#/definitions/alibabaproductSingleObj")
 *     ),
 *     @SWG\Definition(
 *          type="object",
 *          definition="alibabaproductSingleObj",
 *          @SWG\Property(property="data", type="object", ref="#/definitions/alibabaproductSingle")
 *     ),
 *     @SWG\Definition(
 *          type="object",
 *          definition="alibabaproductListData",
 *          required={"errno", "errmsg", "result"},
 *          @SWG\Property(property="errno", type="integer", format="int32", description="编码"),
 *          @SWG\Property(property="errmsg", type="string", format="string", description="错误提示信息"),
 *          @SWG\Property(property="result", ref="#/definitions/alibabaproductListObj"),
 *     ),
 *     @SWG\Definition(
 *          type="object",
 *          definition="alibabaproductListObj",
 *          @SWG\Property(property="data", type="object", ref="#/definitions/alibabaproductData"),
 *          @SWG\Property(property="meta", ref="#/definitions/meta")
 *     ),
 *     @SWG\Definition(
 *          type="array",
 *          definition="alibabaproductData",
 *          @SWG\Items(
 *              title="data", ref="#/definitions/alibabaproductSingle"
 *          )
 *     ),
 *     @SWG\Definition(
 *          type="object",
 *          definition="alibabaproductSingle",
 *          @SWG\Property(property="product_id", type="string", format="string",  description="584051070147"),
 *          @SWG\Property(property="category_id", type="integer", format="int32",  description="商品分类"),
 *          @SWG\Property(property="title", type="string", format="string",  description="商品标题"),
 *          @SWG\Property(property="description", type="string", format="string",  description="商品详情"),
 *          @SWG\Property(property="price", type="string", format="string",  description="原价"),
 *          @SWG\Property(property="promotion_price", type="string", format="string",  description="超买价"),
 *          @SWG\Property(property="img_url", type="string", format="string",  description="商品首图"),
 *          @SWG\Property(property="images", type="string", format="string",  description="主图列表(使用相对路径,需要增加域名:https://cbu01.alicdn.com/)"),
 *          @SWG\Property(property="channel_price", type="string", format="string",  description="渠道专属价"),
 *          @SWG\Property(property="sales", type="integer", format="int32",  description="销量"),
 *          @SWG\Property(property="reference_price", type="string", format="string",  description="参考价格(返回价格区间,可能为空)"),
 *          @SWG\Property(property="supplier_login_id", type="string", format="string",  description="供应商loginId"),
 *          @SWG\Property(property="main_video", type="string", format="string",  description="主图视频播放地址"),
 *          @SWG\Property(property="product_cargo_number", type="string", format="string",  description="商品货号(产品属性中的货号)"),
 *          @SWG\Property(property="alibaba_stats", type="string", format="string",  description="1688商品状态(published:上网状态,member expired:会员撤销,auto expired:自然过期,expired:过期(包含手动过期与自动过期),member deleted:会员删除,modified:修改,new:新发,deleted:删除,TBD:to be delete,approved:审批通过,auditing:审核中,untread:审核不通过)"),
 *          @SWG\Property(property="stats", type="integer", format="int32",  description="状态"),
 *          @SWG\Property(property="redemption", type="integer", format="int32",  description="允许积分兑换(0为否,1为是,2为即能积分兑换又能销售,默认0)"),
 *          @SWG\Property(property="integral", type="string", format="string",  description="兑换所需积分"),
 *          @SWG\Property(property="quality_level", type="integer", format="int32",  description="质量星级(0-5)"),
 *          @SWG\Property(property="support_online_trade", type="integer", format="int32",  description="是否支持网上交易(1为支持,0为不支持,默认1)"),
 *          @SWG\Property(property="mix_whole_sale", type="integer", format="int32",  description="是否支持混批(0为否,1为是,默认1)"),
 *          @SWG\Property(property="price_auth", type="integer", format="int32",  description="是否价格私密信息(1为是,0为否,默认1)"),
 *          @SWG\Property(property="price_ranges", type="string", format="string",  description="价格区间json字符串"),
 *          @SWG\Property(property="amount_on_sale", type="integer", format="int32",  description="可售数量"),
 *          @SWG\Property(property="unit", type="string", format="string",  description="记件单位"),
 *          @SWG\Property(property="min_order_quantity", type="integer", format="int32",  description="最小起订量，范围是1-99999"),
 *          @SWG\Property(property="batch_number", type="integer", format="int32",  description="每批数量，默认为空或者非零值，该属性不为空时sellunit为必填"),
 *          @SWG\Property(property="sell_unit", type="string", format="string",  description="售卖单位，如果为批量售卖，代表售卖的单位，该属性不为空时batch_number为必填，例如1'手'=12'件'的'手'"),
 *          @SWG\Property(property="quote_type", type="integer", format="int32",  description="0-无SKU按数量报价,1-有SKU按规格报价,2-有SKU按数量报价"),
 *          @SWG\Property(property="consign_price", type="string", format="string",  description="分销基准价。代销场景均使用该价格。有SKU商品查看skuInfo中的consignPrice"),
 *          @SWG\Property(property="cps_suggest_price", type="string", format="string",  description="CPS建议价（单位：元)"),
 *          @SWG\Property(property="platform_price", type="string", format="string",  description="平台售价"),
 *          @SWG\Property(property="recommennd", type="integer", format="int32",  description="是否推荐(0为否,1为是,默认0)"),
 *          @SWG\Property(property="platform_sales", type="integer", format="int32",  description="平台总销量"),
 *          @SWG\Property(property="fake_platform_sales", type="integer", format="int32",  description="假的平台销量"),
 *          @SWG\Property(property="sales_in_30_days", type="integer", format="int32",  description="平台30天内销量"),
 *          @SWG\Property(property="fake_favours", type="integer", format="int32",  description="假的收藏数"),
 *          @SWG\Property(property="favours", type="integer", format="int32",  description="收藏数"),
 *          @SWG\Property(property="fake_views", type="integer", format="int32",  description="假的曝光数"),
 *          @SWG\Property(property="views", type="integer", format="int32",  description="曝光量"),
 *          @SWG\Property(property="fake_clicks", type="integer", format="int32",  description="假的点击数"),
 *          @SWG\Property(property="clicks", type="integer", format="int32",  description="商品点击数"),
 *          @SWG\Property(property="rebate_integral", type="string", format="string",  description="拼团失败的金豆返还比例"),
 *          @SWG\Property(property="parent_rebate_integral", type="string", format="string",  description="上级可获得金豆(单位:%)"),
 *          @SWG\Property(property="sub_rebate_integral", type="string", format="string",  description="上上级可获得金豆(单位:%)"),
 *          @SWG\Property(property="is_booking", type="integer", format="int32",  description="是否为机器拼单(1为是,0为否,默认0)"),
 *          @SWG\Property(property="created_at", type="string", format="string",  description="创建时间"),
 *          @SWG\Property(property="updated_at", type="string", format="string",  description="更新时间"),
 *     )
 * )
 */
class AlibabaproductModel extends BaseModel
{
    /**
     * 584051070147
     */
    public $product_id = null;

    /**
     * 商品分类
     */
    public $category_id = null;

    /**
     * 商品标题
     */
    public $title = null;

    /**
     * 商品详情
     */
    public $description = null;

    /**
     * 原价
     */
    public $price = null;

    /**
     * 超买价
     */
    public $promotion_price = null;

    /**
     * 商品首图
     */
    public $img_url = null;

    /**
     * 主图列表(使用相对路径,需要增加域名:https://cbu01.alicdn.com/)
     */
    public $images = "";

    /**
     * 渠道专属价
     */
    public $channel_price = null;

    /**
     * 销量
     */
    public $sales = null;

    /**
     * 参考价格(返回价格区间,可能为空)
     */
    public $reference_price = null;

    /**
     * 供应商loginId
     */
    public $supplier_login_id = null;

    /**
     * 主图视频播放地址
     */
    public $main_video = null;

    /**
     * 商品货号(产品属性中的货号)
     */
    public $product_cargo_number = null;

    /**
     * 1688商品状态(published:上网状态,member expired:会员撤销,auto expired:自然过期,expired:过期(包含手动过期与自动过期),member deleted:会员删除,modified:修改,new:新发,deleted:删除,TBD:to be delete,approved:审批通过,auditing:审核中,untread:审核不通过)
     */
    public $alibaba_stats = null;

    /**
     * 状态
     */
    public $stats = null;

    /**
     * 允许积分兑换(0为否,1为是,2为即能积分兑换又能销售,默认0)
     */
    public $redemption = null;

    /**
     * 兑换所需积分
     */
    public $integral = null;

    /**
     * 质量星级(0-5)
     */
    public $quality_level = null;

    /**
     * 是否支持网上交易(1为支持,0为不支持,默认1)
     */
    public $support_online_trade = null;

    /**
     * 是否支持混批(0为否,1为是,默认1)
     */
    public $mix_whole_sale = null;

    /**
     * 是否价格私密信息(1为是,0为否,默认1)
     */
    public $price_auth = null;

    /**
     * 价格区间json字符串
     */
    public $price_ranges = "";

    /**
     * 可售数量
     */
    public $amount_on_sale = null;

    /**
     * 记件单位
     */
    public $unit = null;

    /**
     * 最小起订量，范围是1-99999
     */
    public $min_order_quantity = null;

    /**
     * 每批数量，默认为空或者非零值，该属性不为空时sellunit为必填
     */
    public $batch_number = null;

    /**
     * 售卖单位，如果为批量售卖，代表售卖的单位，该属性不为空时batch_number为必填，例如1'手'=12'件'的'手'
     */
    public $sell_unit = null;

    /**
     * 0-无SKU按数量报价,1-有SKU按规格报价,2-有SKU按数量报价
     */
    public $quote_type = null;

    /**
     * 分销基准价。代销场景均使用该价格。有SKU商品查看skuInfo中的consignPrice
     */
    public $consign_price = null;

    /**
     * CPS建议价（单位：元)
     */
    public $cps_suggest_price = null;

    /**
     * 平台售价
     */
    public $platform_price = null;

    /**
     * 是否推荐(0为否,1为是,默认0)
     */
    public $recommennd = null;

    /**
     * 平台总销量
     */
    public $platform_sales = null;

    /**
     * 假的平台销量
     */
    public $fake_platform_sales = null;

    /**
     * 平台30天内销量
     */
    public $sales_in_30_days = null;

    /**
     * 假的收藏数
     */
    public $fake_favours = null;

    /**
     * 收藏数
     */
    public $favours = null;

    /**
     * 假的曝光数
     */
    public $fake_views = null;

    /**
     * 曝光量
     */
    public $views = null;

    /**
     * 假的点击数
     */
    public $fake_clicks = null;

    /**
     * 商品点击数
     */
    public $clicks = null;

    /**
     * 拼团失败的金豆返还比例
     */
    public $rebate_integral = null;

    /**
     * 上级可获得金豆(单位:%)
     */
    public $parent_rebate_integral = null;

    /**
     * 上上级可获得金豆(单位:%)
     */
    public $sub_rebate_integral = null;

    /**
     * 是否为机器拼单(1为是,0为否,默认0)
     */
    public $is_booking = null;

    /**
     * 创建时间
     */
    public $created_at = null;

    /**
     * 更新时间
     */
    public $updated_at = null;
    /**
     * DAO对象
     */
    public $obj = '';

    /**
     * DAO对象数组
     */
    public $data = [];

    /**
     * 翻页对象
     */
    public $meta = null;

    /**
     * 当前页
     */
    public $page = 1;

    /**
     * 每页显示条数
     */
    public $page_size = 10;

    /**
     * 主键数组
     */
    public $primary_key_arr = ["product_id"];

    /**
     * 自增字段数组
     */
    public $auto_increment_key_arr = [];

    /**
     * 唯一字段
     */
    public $unique_key_arr = '';

    /**
     * 单例实例
     */
    static public $instance = null;

    /**
     * @return AlibabaproductModel|null
     * @throws ModelSqlException
     */
    static public function getInstance()
    {
        if (is_null(self::$instance)) {
            self::$instance = new self();
        }
        return self::$instance;
    }

    /**
     * AlibabaproductModel constructor.
     * @throws ModelSqlException
     */
    public function __construct()
    {
        parent::__construct(str_replace("Model", "", substr(get_class($this), strrpos(get_class($this), "\\") + 1)));
        $this->meta = new \stdClass();
    }

    /**
     * @throws ModelException
     */
    public function __clone()
    {
        throw new ModelException(
            str_replace('%s', get_class($this), ModelException::INSTANCE_NOT_ALLOW_TO_CLONE), ModelException::INSTANCE_NOT_ALLOW_TO_CLONE_NO);
    }

    public function __destruct()
    {
        self::$instance = null;
    }

    /**
     * set属性
     *
     * __set.
     * @param string $name 参数名
     * @param string $value 参数值
     * @return $this
     */
    public function __set($name = "", $value = "")
    {
        $this->$name = $value;
        return $this;
    }

    /**
     * get属性
     *
     * __get.
     * @param string $name 参数名
     * @return mixed
     */
    public function __get($name = "")
    {
        return $this->$name;
    }

    /**
     * 创建alibabaproductModel
     *
     * @return mixed
     * @throws ModelDriverException
     * @throws ModelReflectionException
     * @throws ModelSqlException
     * @throws ModelException
     */
    public function insert()
    {
        return $this->insertRecord();
    }

    /**
     * 编辑alibabaproductModel
     *
     * @return mixed
     * @throws ModelDriverException
     * @throws ModelReflectionException
     * @throws ModelSqlException
     * @throws ModelException
     */
    public function update()
    {
        return $this->updateRecord();
    }

    /**
     * 删除alibabaproductModel，需先指定主键
     *
     * @return mixed
     * @throws ModelDriverException
     * @throws ModelReflectionException
     * @throws ModelSqlException
     * @throws ModelException
     */
    public function delete()
    {
        return $this->deleteRecord();
    }

    /**
     * 根据主键查询alibabaproductModel，获取单条记录
     *
     * find.
     * @param int $primary_key 主键编号
     * @return $this
     * @throws ModelException
     * @throws ModelReflectionException
     */
    public function find($primary_key = 0)
    {
        $result = $this->findByPrimaryKey($primary_key);

        $this->setModelProperty($result);

        return $this;
    }

    /**
     * 根据条件数组查询alibabaproductModel，获取多条记录
     *
     * findOneBy.
     * @param array $condition 查询条件
     * @return $this
     * @throws ModelDriverException
     * @throws ModelException
     * @throws ModelReflectionException
     * @throws ModelSqlException
     */
    public function findOneBy($condition = [])
    {
        $result = $this->findRecordBy($condition);

        $this->setModelProperty($result);

        return $this;
    }

    /**
     * 根据条件数组查询alibabaproductModel，获取多条记录
     *
     * findBy.
     * @param array $condition 查询条件
     * @return $this
     * @throws ModelDriverException
     * @throws ModelException
     * @throws ModelReflectionException
     * @throws ModelSqlException
     */
    public function findBy($condition = [])
    {
        $count = $this->getCount($condition);
        $total = $count->fetchColumn();

        $this->data = [];
        $alib_obj = $this->findRecordBy($condition, $this->page, $this->page_size);

        $this->genMeta($total);
        $this->setModelProperty($alib_obj, true);

        return $this;
    }

    /**
     * 批量插入alibabaproductModel
     *
     * @return mixed
     * @throws ModelDriverException
     * @throws ModelException
     * @throws ModelSqlException
     */
    public function batchInsert()
    {
        return $this->batchInsertRecord();
    }

    /**
     * 批量删除alibabaproductModel
     *
     * @throws ModelDriverException
     * @throws ModelException
     * @throws ModelSqlException
     */
    public function batchDelete()
    {
        $this->batchDeleteRecord();
    }

    /**
     * 生成批量生成update的sql
     *
     * @return bool|string
     * @throws ModelDriverException
     * @throws ModelException
     * @throws ModelSqlException
     */
    public function genBatchUpdateSql()
    {
        return $this->_genBatchUpdateSql();
    }

}
